const WXAPI = require('apifm-wxapi')
const AUTH = require('../../utils/auth')

let interstitialAd = null

Page({

  /**
   * 页面的初始数据
   */
  data: {
    minOrderAmt: 0,
    shippingAmt: 0,
    startTime: '08:00',
    endTime: '18:00'
  },
  onShow: function(){
    WXAPI.findSelfSetting().then(res => {
      if(res.retCode === '200'){
        this.setData({
          minOrderAmt: res.data.minOrderAmt,
          shippingAmt: res.data.shippingAmt,
          startTime: res.data.startWorkTime,
          endTime: res.data.endWorkTime
        })
      }
    })
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  bindTimeChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      time: e.detail.value
    })
  },
  bindMinInput: function (e) {
    this.setData({
      minOrderAmt: e.detail.value
    })
  },
  bindShipInput: function (e) {
    this.setData({
      shippingAmt: e.detail.value
    })
  },
  bindStartTimeChange: function(e){
    this.setData({
      startTime: e.detail.value
    })
  },
  submit: function(){
    const { startTime, endTime, shippingAmt, minOrderAmt} = this.data

    const postData = {
      "endWorkTime": endTime,
      minOrderAmt,
      shippingAmt,
      "startWorkTime": startTime
    }
    WXAPI.selfSetting(postData).then((res) => {
      console.log('---', res)
    })
  },
  bindEndTimeChange: function(e){
    this.setData({
      endTime: e.detail.value
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})